package com.gooluke;

import java.lang.ref.WeakReference;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author gooluke
 * description
 * datetime 2025-04-10 11:00
 */
public class ThreadMain {

    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 2, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10), new ThreadPoolExecutor.AbortPolicy());
        threadPoolExecutor.execute(()-> System.out.println("随便执行了一个任务"));
        WeakReference<ThreadPoolExecutor> weakReference = new WeakReference<>(threadPoolExecutor);
        threadPoolExecutor = null;
        System.gc();
        if (weakReference.get() == null) {
            System.out.println("线程池已经被回收");
        }
    }

}
